const path = require("node:path");
const destinationName = "dist-browser";
const destinationPath = path.resolve(__dirname, destinationName);

module.exports = [
  {
    mode: "development",
    entry: "./src/index.ts",
    devtool: false,
    output: {
      filename: "euv.umd.js",
      path: destinationPath,
      library: {
        type: "umd",
      },
    },
    resolve: {
      extensions: [".tsx", ".ts", ".js"],
    },
    module: {
      rules: [
        {
          test: /\.ts$/,
          use: "swc-loader",
          exclude: /node_modules/, //排除 node_modules 目录
        },
      ],
    },
    devServer: {
      watchFiles: ["./src/**", "./example/**"],
      static: [
        {
          directory: path.resolve(__dirname, "example"),
          publicPath: "/example",
        },
        {
          directory: destinationPath,
          publicPath: "/" + destinationName,
        },
      ],

      port: 8080,
      hot: true,
      open: ["/example"],
    },
  },
  {
    mode: "production",
    entry: "./src/index.ts",
    // devtool: "source-map",
    output: {
      filename: "euv.umd.production.js",
      path: destinationPath,
      library: {
        type: "umd",
      },
    },
    optimization: {
      minimize: true,
    },
    resolve: {
      extensions: [".tsx", ".ts", ".js"],
    },
    module: {
      rules: [
        {
          test: /\.ts$/,
          use: "swc-loader",
          exclude: /node_modules/, //排除 node_modules 目录
        },
      ],
    },
  },
  {
    mode: "production",
    entry: "./src/index.ts",
    // devtool: "source-map",
    output: {
      filename: "euv.global.production.js",
      path: destinationPath,
      library: {
        type: "global",
      },
    },
    optimization: {
      minimize: true,
    },
    resolve: {
      extensions: [".tsx", ".ts", ".js"],
    },
    module: {
      rules: [
        {
          test: /\.ts$/,
          use: "swc-loader",
          exclude: /node_modules/, //排除 node_modules 目录
        },
      ],
    },
  },
  {
    mode: "development",
    entry: "./src/index.ts",
    devtool: false,
    experiments: {
      outputModule: true,
    },
    output: {
      filename: "euv.esm.js",
      path: destinationPath,
      library: {
        type: "module",
      },
    },
    resolve: {
      extensions: [".tsx", ".ts", ".js"],
    },
    module: {
      rules: [
        {
          test: /\.ts$/,
          use: "swc-loader",
          exclude: /node_modules/, //排除 node_modules 目录
        },
      ],
    },
  },
  {
    mode: "production",
    entry: "./src/index.ts",
    // devtool: "source-map",
    experiments: {
      outputModule: true,
    },
    output: {
      filename: "euv.esm.production.js",
      path: destinationPath,
      library: {
        type: "module",
      },
    },
    optimization: {
      minimize: true,
    },
    resolve: {
      extensions: [".tsx", ".ts", ".js"],
    },
    module: {
      rules: [
        {
          test: /\.ts$/,
          use: "swc-loader",
          exclude: /node_modules/, //排除 node_modules 目录
        },
      ],
    },
  },
];
